package com.time.company.db.dao.impl;


import com.time.company.db.dao.BaseDao;
import com.time.company.db.model.DynamicsModel;
import com.time.company.db.model.PicModel;
import com.time.company.servermodel.dynamics.Pic;

import org.litepal.crud.DataSupport;

import java.util.List;

/**
 * 动态操作类
 * Created by Bing on 2016/9/8.
 * E-mail is tx16bing@163.com
 */
public class DynamicsDao extends BaseDao<DynamicsModel> {

    @Override
    public boolean save(DynamicsModel bean) {
//        delete(bean);
        List<Pic> pics = bean.getPicList();
        if (pics != null){
            for (Pic pic : pics){
                PicModel picModel = new PicModel(pic);
                new PicDdao().save(picModel);
            }
        }
        return bean.save();
    }

    @Override
    public int delete(DynamicsModel bean) {
        // 删除缓存数据
        return DataSupport.deleteAll(DynamicsModel.class,
                "dynamicsid=?",
                bean.getDynamicsId());
    }

    @Override
    public List<DynamicsModel> find() {
        return DataSupport.findAll(DynamicsModel.class);
    }
}
